﻿<!--
 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
 ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 PARTICULAR PURPOSE.

 Copyright (c) Microsoft Corporation. All rights reserved
-->
<local:HiloPage
    x:Class="Hilo.CropImageView"
    x:Uid="Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Hilo"
    xmlns:common="using:Hilo.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=CropImageVM}">

    <Page.Resources>
        <common:BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
        <ControlTemplate x:Key="HiloCroppingOverlayTemplate" TargetType="ContentControl">
            <Grid>
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                   
                       HorizontalAlignment="Stretch" 
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Top" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                    
                       HorizontalAlignment="Left"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Stretch" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                   
                       HorizontalAlignment="Right"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Stretch" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                   
                       HorizontalAlignment="Stretch"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Bottom" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                     
                       HorizontalAlignment="Left"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Top" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                    
                       HorizontalAlignment="Right"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Top" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                    
                       HorizontalAlignment="Left"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Bottom" />
                <Thumb x:ConnectionId='0' Canvas.ZIndex="1"
                                                    
                       HorizontalAlignment="Right"
                       Style="{StaticResource HiloCroppingOverlayThumbStyle}"
                       VerticalAlignment="Bottom" />
                <ContentPresenter Content="{TemplateBinding ContentControl.Content}" />
            </Grid>
        </ControlTemplate>
    </Page.Resources>

    <Grid x:Name="ContentRoot"
          d:DataContext="{Binding Source={d:DesignInstance Type=local:DesignTimeData, IsDesignTimeCreatable=True}}"
          Background="{StaticResource HiloPageBackgroundBrush}">
        <!-- Crop Image Grid.Row="1" -->
        <Grid x:Name="CropImageGrid"
              Margin="50,50,50,110">
            <TextBlock x:Name="PageTitle"
                       x:Uid="CropImagePageTitle"
                       Style="{StaticResource SnappedPageHeaderTextStyle}"
                       VerticalAlignment="Top"
                       Visibility="Collapsed"/>
            <Image x:ConnectionId='0' x:Name="Photo" 
                   AutomationProperties.AutomationId="ImageControl"
                   HorizontalAlignment="Center" 
                   VerticalAlignment="Center" 
                                              
                   Source="{Binding Image}"/>
            <ProgressRing IsActive="{Binding InProgress}" 
                          Foreground="{StaticResource HiloHighlightBrush}"
                          Height="60"
                          Width="60"/>
            <!-- Note: Hilo's crop overlay control does not support keyboard accessibility. To implement keyboard accessibility for your -->
            <!-- own controls, see http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh868161(v=win.10).aspx -->
            <Canvas x:Name="CropCanvas" HorizontalAlignment="Left" VerticalAlignment="Top">
                <ContentControl x:Name="CropOverlay"
                                Canvas.Left="{Binding CropOverlayLeft}"
                                Canvas.Top="{Binding CropOverlayTop}"
                                Height="{Binding CropOverlayHeight}"
                                MinHeight="100"
                                MinWidth="100"
                                Template="{StaticResource HiloCroppingOverlayTemplate}"
                                Visibility="{Binding Path=IsCropOverlayVisible, Converter={StaticResource BoolToVisConverter}}"
                                Width="{Binding CropOverlayWidth}">
                    <Grid x:ConnectionId='0' Background="Transparent"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                                                        >
                    </Grid>
                </ContentControl>
            </Canvas>
        </Grid>
        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CancelButton"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CancelButtonNoLabel"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>       
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SaveButton"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SaveButtonNoLabel"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Snapped">
                    <Storyboard>                  
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CancelButton"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CancelButtonNoLabel"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SaveButton"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ResumeCropStackPanel"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CropCanvas"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CropImageGrid"
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="20,50,20,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitle"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>

    <local:HiloPage.BottomAppBar>
        <AppBar x:Name="CropImageBottomAppBar" 
                x:Uid="AppBar"
                AutomationProperties.AutomationId="CropImageBottomAppBar"
                IsOpen="True"
                IsSticky="{Binding IsAppBarSticky}" 
                Padding="10,0,10,0">
            <Grid>
                <StackPanel x:Name="ResumeCropStackPanel"
                            HorizontalAlignment="Left"
                            Orientation="Horizontal"
                            Visibility="Collapsed">
                    <Button Command="{Binding ResumeCropCommand}"
                            Style="{StaticResource CropAppBarButtonNoLabelStyle}"
                            Tag="Resume Crop">
                        <ToolTipService.ToolTip>
                            <ToolTip x:Uid="ResumeCropAppBarButtonToolTip" />
                        </ToolTipService.ToolTip>
                    </Button>
                </StackPanel>
                <StackPanel HorizontalAlignment="Right" 
                            Orientation="Horizontal">
                    <Button x:Name="CancelButton"
                            x:Uid="CancelAppBarButton"
                            Command="{Binding CancelCommand}" 
                            Style="{StaticResource CancelAppBarButtonStyle}" 
                            Tag="Cancel" />
                    <Button x:Name="CancelButtonNoLabel"
                            Command="{Binding CancelCommand}"
                            Style="{StaticResource CancelAppBarButtonNoLabelStyle}"
                            Tag="Cancel"
                            Visibility="Collapsed">
                        <ToolTipService.ToolTip>
                            <ToolTip x:Uid="CancelCropAppBarButtonToolTip" />
                        </ToolTipService.ToolTip>
                    </Button>
                    <Button x:Name="SaveButton"
                            x:Uid="AcceptAppBarButton"
                            Command="{Binding SaveCommand}" 
                            Style="{StaticResource AcceptAppBarButtonStyle}" 
                            Tag="Save" />
                    <Button x:Name="SaveButtonNoLabel"
                            Command="{Binding SaveCommand}"
                            Style="{StaticResource AcceptAppBarButtonNoLabelStyle}"
                            Tag="Save"
                            Visibility="Collapsed">
                        <ToolTipService.ToolTip>
                            <ToolTip x:Uid="AcceptCropAppBarButtonToolTip" />
                        </ToolTipService.ToolTip>
                    </Button>
                </StackPanel>
            </Grid>
        </AppBar>
    </local:HiloPage.BottomAppBar>
</local:HiloPage>

